<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html ng-app="myApp">
<head>
    <title></title>
</head>
<body ng-controller="myCtrl">
<table>
    <tr>
        <td>id</td>
        <td>name</td>
        <td>操作</td>
    </tr>
    <tr ng-repeat="student in students">
        <td ng-bind="student.id"></td>
        <td ng-bind="student.name"></td>
        <td>
            <button ng-click="delete(student.id)">删除</button>
        </td>
    </tr>
</table>
<table border="0">
    <tr>
        <td>id</td>
        <td><input type="text" ng-model="student.id"></td>
    </tr>
    <tr>
        <td>name</td>
        <td><input type="text" ng-model="student.name"></td>
    </tr>
    <tr>
        <td>
            <button ng-click="save()">保存</button>
            <button ng-click="query()">刷新</button>
            <button ng-click="update()">修改</button>
            <button ng-click="clear()">清空</button>
        </td>
        <td></td>
    </tr>
</table>
<script src="/angular.min.js"></script>
<script src="/angular-resource.min.js"></script>
<script>
    var myApp = angular.module('myApp', ['ngResource']);
    myApp.controller('myCtrl', function ($scope, $http) {
        $scope.query = function () {
            $http.get('/student').success(function (resp) {
                $scope.students = resp;
            });
        }
        $scope.query();
        $scope.save = function () {
            $http.post('/student', $scope.student).success(function (resp) {
                console.log(resp);
                $scope.query();
            });
        }
        $scope.update = function () {
            $http.put('/student', $scope.student).success(function (resp) {
                console.log(resp);
                $scope.query();
            });
        }
        $scope.delete = function (id) {
            $http.delete('/student/' + id).success(function (resp) {
                console.log(resp);
                $scope.query();
            });
        }
        $scope.clear = function () {
            $scope.student = {};
        }
    });
</script>
</body>
</html>
